package cn.wolfcode.trip.base.domain;

import cn.wolfcode.trip.base.util.JSONUtil;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
import org.springframework.format.annotation.DateTimeFormat;

import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import java.util.regex.Pattern;

/**
 * 保险产品信息
 */
@Setter
@Getter
@ToString
public class InsuranceProduct extends BaseDomain {
    public static final int STATE_DISABLE = -1;// 禁用
    public static final int STATE_NOMAL = 0;//正常
    public static final int STATE_HOT = 1;//推荐

    // 产品类型
    private String productName;

    // 保险类型
    private Insurance insurance;

    // 价格
    private BigDecimal price;

    // 产品创建时间
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    private Date createTime;

    // 产品状态 禁用-1 正常0 推荐1
    private Integer state;

    // 保险产品封面
    private String coverUrl;

    // 保险产品内容
    private InsuranceContent insuranceContent;//攻略文章内容

    // 获取json数据
    public String getJson() {
        Map<String, Object> map = new HashMap<>();
        map.put("id", id);
        map.put("productName", productName);
        map.put("price", price);
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        map.put("createTime", sdf.format(createTime));
        map.put("state", state);
        map.put("coverUrl", coverUrl);
        if (insurance != null) {
            map.put("insuranceId", insurance.getId());
            map.put("insuranceName", insurance.getName());
        }
        if (insuranceContent != null) {
            map.put("faq", insuranceContent.getFaq());
        }


        return JSONUtil.toJSONString(map);
    }
}